/*创作剪辑——长视频*/
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";


// 新增修改 长视频
export async function addLongVideo(data) {
  const res = await request.post('/business/longvideoediting/add', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 长视频——生成视频
export async function getGenerateVideo(form) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    username:form.username,  // 用户id
    id:form.id,  //长视频任务id
    generationTimes:form.maximumCount, //生成次数
    duration:form.duration // 生成视频时长
  };
  let url = `/business/longvideoediting/generateVideo${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 使用id查询单条长视频数据
export async function queryLongDetail(data) {
  const res = await request.post('/business/longvideoediting/selectByKeyId', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 不分页查询 长视频
export async function queryLongInfo(data) {
  const res = await request.post('/business/longvideoediting/pageList', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//  分页查询 长视频
export async function queryLongList(data) {
  const res = await request.post('/business/longvideoediting/page', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//  删除 长视频
export async function delLongList(data) {
  const res = await request.post('/business/longvideoediting/delete', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/* 混剪“视频文字” api start */


// 获取所有字体
export async function fontListAll () {
  const ts = new Date().getTime()
  const ua = navigator.userAgent
  const us = {
    ts,
    ua
  }
  // eslint-disable-next-line no-undef
  let url = `/business/montage/fontlist/all${object2Url(us)}`
  const res = await request.get(url, us)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}

// 根据条件获取 字体大小数据
export async function getFontSize (data) {
  const res = await request.post('/business/montage/fontsize/list', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}

// 校验及构建剪辑工程脚本  /business/montage/project/checkAndBuild
export async function checkAndBuild (data) {
  const res = await request.post('/business/montage/scripts/checkAndBuild', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}


// 删除剪辑工程文字
export async function deleteProjectText (data) {
  const res = await request.post('/business/montage/projecttext/deleteProjectText', data)
  if (res.data.code === 2000) {
    return res.data
  }
  return Promise.reject(new Error(res.data.msg))
}


// 保存剪辑工程文字
export async function saveOrUpdateText (data) {
  const res = await request.post('/business/montage/projecttext/saveOrUpdate', data)
  if (res.data.code === 2000) {
    return res.data
  }
  return Promise.reject(new Error(res.data.msg))
}

// “视频文字” ——文字效果 api

/**
 * 获取md5加密加盐参数
 */
export async function textlist () {
  const ts = new Date().getTime()
  const ua = navigator.userAgent
  const us = {
    ts,
    ua
  }
  let url = `/business/montage/textlist/all${object2Url(us)}`
  const res = await request.get(url, us)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}

/* 混剪“视频文字” api end */
